const webpack = require('webpack')
const WebpackConfig = require('./webpack.config')

 const MemoryFileSystem = require('memory-fs');
 let fs=new MemoryFileSystem();

console.log(WebpackConfig)
// const compiler = webpack(WebpackConfig,function(a,b){
// 	console.log("没有这个回调函数还不行，真奇怪",b.getStats)
// })

const compiler = webpack(WebpackConfig);
compiler.hooks.done.tap('test', function(){
	console.log("改动了文件");
	compiler.run((err, stats) => {
		console.log(fs.data['D:'].webpacktest.__build__['main.js']);
		const content = fs.readFileSync('D:/webpacktest/__build__/main.js', 'utf-8');
		console.log(content);
		compiler.close((closeErr) => {});
	});
});
compiler.hooks.watchRun.tap(
    'test',
    (comp, callback) => {
		console.log("监听中");
    }
);

//加了这个才能保持一直存在
compiler.watch({aggregateTimeout: 300}, (err) => {
      if (err) {
        context.log.error(err.stack || err);
        if (err.details) {
          context.log.error(err.details);
        }
      }
 });
 

 compiler.outputFileSystem =fs